BUILDER R Functions
neighbours()
The neighbours()
function creates a neighbours table listing neighbours for each catchment, which is an input to builder()
.
For an sf object of catchments with unique CATCHNUM id’s, calculates a list of neighbouring CATCHNUM pairs and returns them in a long tibble. Neighbours are defined as having at least on point in common (within 0.1m).
Usage
neighbours(
catchments_sf )
Arguments
- catchments_sf: sf object of the catchments dataset with a unique identifier column: CATCHNUM.
📤 Output
A tibble of neighbouring pairs with columns CATCHNUM and neighbours.
Examples
Running the examples
Download and unzip BEACONs R Tools
Create the folder structure
# Set working directory
setwd("your/path/to/downloads")
<- getwd()
dirpath
# Create the folder structure
<- c("R","data","Builder_input")
treedir for(d in treedir){
if (!dir.exists(file.path(dirpath, d))) {
dir.create(file.path(dirpath, d), recursive = TRUE)
} }
- Run the examples below.
library(dplyr)
library(sf)
library(utils)
source("./R/builder.R")
# Use all catchments as seeds with a single area target
<- readRDS("data/catchments_sample.rds")
catchments_sample neighbours(catchments_sf = catchments_sample)
# save neighbours as csv
<- neighbours(catchments_sf = catchments_sample)
neighbour write.csv(neighbour, file=file.path(dirpath,"Builder_input/neighbours.csv"), row.names=FALSE)